< previous page page_219 next page >

Page 219
axes, performing the reflection and then translating the image back. For example, to reflect a pixel across the line y = y0, you would subtract y0 from the pixel's Y coordinate, multiply by 1 to reflect the point, and then add y0 to the result. Putting these steps together, you can write an equation for the new location y_out in terms of the old location y_in.
e10a6a0a59f035e870d90cca05b85fce.gif
y_out = (y_in - y0) * (-1) + y0
This simplifies to:
e10a6a0a59f035e870d90cca05b85fce.gif
y_out = 2 * y0 - y_in
Solving this equation for y_in gives:
e10a6a0a59f035e870d90cca05b85fce.gif
y_in = 2 * y0 - y_out
You can use this equation to build a MapPixel subroutine for use with the transformation framework used by other programs in this chapter.
While you could reflect an image vertically or horizontally in this way, PaintPicture is much simpler and faster. The following code shows how you can use PaintPicture to reflect an image vertically. The negative value for the source image's height makes PaintPicture flip the image vertically.
e10a6a0a59f035e870d90cca05b85fce.gif
Dim wid As Single
Dim hgt As Single

    wid = picOriginal.ScaleWidth
    hgt = picOriginal.ScaleHeight
    picResult.PaintPicture _
        picOriginal.Picture, _
        0, 0, wid, hgt, _
        0, hgt, wid, -hgt
Complex Reflection
A more interesting example reflects an image across a line that is not parallel to the X or Y axis. You can accomplish this transformation using simple translation, rotation, and reflection by following these steps:
1. Translate so that the line of reflection intersects the origin.
2. Rotate so that the line of reflection lies along the X axis.
3. Reflect across the X axis by multiplying the pixels' Y values by 1.
4. Reverse the previous rotation.
5. Reverse the previous translation.

 
< previous page page_219 next page >